<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>Luat开源项目脚本lib</title>
    <link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>script_LuaTask lib</h1>

<ul>
  <li><a href="../index.html">Index</a></li>
</ul>

<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
</ul>


<h2>Modules</h2>
<ul class="nowrap">
  <li><a href="../modules/aLiYun.html">aLiYun</a></li>
  <li><a href="../modules/aLiYunOta.html">aLiYunOta</a></li>
  <li><a href="../modules/agps.html">agps</a></li>
  <li><a href="../modules/agpsHxxt.html">agpsHxxt</a></li>
  <li><a href="../modules/agpsZkw.html">agpsZkw</a></li>
  <li><strong>audio</strong></li>
  <li><a href="../modules/cc.html">cc</a></li>
  <li><a href="../modules/clib.html">clib</a></li>
  <li><a href="../modules/common.html">common</a></li>
  <li><a href="../modules/console.html">console</a></li>
  <li><a href="../modules/errDump.html">errDump</a></li>
  <li><a href="../modules/ftp.html">ftp</a></li>
  <li><a href="../modules/gps.html">gps</a></li>
  <li><a href="../modules/gpsHxxt.html">gpsHxxt</a></li>
  <li><a href="../modules/gpsZkw.html">gpsZkw</a></li>
  <li><a href="../modules/http.html">http</a></li>
  <li><a href="../modules/lbsLoc.html">lbsLoc</a></li>
  <li><a href="../modules/led.html">led</a></li>
  <li><a href="../modules/link.html">link</a></li>
  <li><a href="../modules/log.html">log</a></li>
  <li><a href="../modules/misc.html">misc</a></li>
  <li><a href="../modules/mqtt.html">mqtt</a></li>
  <li><a href="../modules/net.html">net</a></li>
  <li><a href="../modules/netLed.html">netLed</a></li>
  <li><a href="../modules/ntp.html">ntp</a></li>
  <li><a href="../modules/nvm.html">nvm</a></li>
  <li><a href="../modules/patch.html">patch</a></li>
  <li><a href="../modules/pb.html">pb</a></li>
  <li><a href="../modules/pins.html">pins</a></li>
  <li><a href="../modules/pm.html">pm</a></li>
  <li><a href="../modules/powerKey.html">powerKey</a></li>
  <li><a href="../modules/record.html">record</a></li>
  <li><a href="../modules/ril.html">ril</a></li>
  <li><a href="../modules/scanCode.html">scanCode</a></li>
  <li><a href="../modules/sim.html">sim</a></li>
  <li><a href="../modules/sms.html">sms</a></li>
  <li><a href="../modules/socket.html">socket</a></li>
  <li><a href="../modules/sys.html">sys</a></li>
  <li><a href="../modules/uiWin.html">uiWin</a></li>
  <li><a href="../modules/update.html">update</a></li>
  <li><a href="../modules/utils.html">utils</a></li>
  <li><a href="../modules/websocket.html">websocket</a></li>
  <li><a href="../modules/wifiScan.html">wifiScan</a></li>
</ul>

</div>

<div id="content">

<h1>Module <code>audio</code></h1>
<p>模块功能：音频播放.</p>
<pre>
<p>
 支持MP3、amr文件播放；
 支持本地TTS播放、通话中TTS播放到对端（需要使用支持TTS功能的core软件）</p>
</pre>
    <h3>Info:</h3>
    <ul>
        <li><strong>Copyright</strong>: openLuat</li>
        <li><strong>Release</strong>: 2018.3.19</li>
        <li><strong>License</strong>: MIT</li>
        <li><strong>Author</strong>: openLuat</li>
    </ul>


<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
	<tr>
	<td class="name" nowrap><a href="#play">
    play (priority, type, path<strong  style="color: gray;">[, vol=4]</strong><strong  style="color: gray;">[, cbFnc=nil]</strong><strong  style="color: gray;">[, dup=nil]</strong><strong  style="color: gray;">[, dupInterval=0]</strong>)
    </a></td>
	<td class="summary">播放音频</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#stop">
    stop (<strong  style="color: gray;">[cbFnc=nil]</strong>)
    </a></td>
	<td class="summary">停止音频播放</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setVolume">
    setVolume (vol)
    </a></td>
	<td class="summary">设置喇叭音量等级</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setCallVolume">
    setCallVolume (vol)
    </a></td>
	<td class="summary">设置通话音量等级</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setMicGain">
    setMicGain (mode, level)
    </a></td>
	<td class="summary">设置mic增益等级
 通话时mic增益在通话建立成功之后设置才有效
 录音mic增益设置后实时生效</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#getVolume">
    getVolume ()
    </a></td>
	<td class="summary">获取喇叭音量等级</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#getCallVolume">
    getCallVolume ()
    </a></td>
	<td class="summary">获取通话音量等级</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setStrategy">
    setStrategy (strategy)
    </a></td>
	<td class="summary">设置优先级相同时的播放策略</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setTTSSpeed">
    setTTSSpeed (speed)
    </a></td>
	<td class="summary">设置TTS朗读速度</td>
	</tr>
	<tr>
	<td class="name" nowrap><a href="#setChannel">
    setChannel (<strong  style="color: gray;">[output=2]</strong><strong  style="color: gray;">[, input=0]</strong>)
    </a></td>
	<td class="summary">设置音频输入、输出通道
 设置后实时生效</td>
	</tr>
</table>

<br/>
<br/>


    <h2 class="section-header "><a name="Functions"></a>Functions</h2>

    <dl class="function">
    <dt>
    <a name = "play"></a>
    <strong  style="color: red;">
    play (priority, type, path<strong  style="color: green;">[, vol=4]</strong><strong  style="color: green;">[, cbFnc=nil]</strong><strong  style="color: green;">[, dup=nil]</strong><strong  style="color: green;">[, dupInterval=0]</strong>)
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">播放音频</pre>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">priority</span>
            <span class="types"><span class="type">number</span></span>
        <pre class="example">音频优先级，数值越大，优先级越高
                   优先级高的播放请求会终止优先级低的播放
                   相同优先级的播放请求，播放策略参考：audio.setStrategy接口</pre>
        </li>
        <li><span class="parameter">type</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
        <pre class="example">音频类型，目前仅支持"FILE"、"TTS"</pre>
        </li>
        <li><span class="parameter">path</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
        <pre class="example">音频文件路径，跟typ有关
               typ为"FILE"时：表示音频文件路径
               typ为"TTS"时：表示要播放的UTF8编码格式的数据</pre>
        </li>
        <li><span class="parameter">vol</span>
            <span class="types"><span class="type">number</span></span>
         [<em>此参数可选，默认值为：</em> 4]
        <pre class="example">播放音量，取值范围0到7，0为静音</pre>
        </li>
        <li><span class="parameter">cbFnc</span>
            <span class="types"><span class="type">function</span></span>
         [<em>此参数可选，默认值为：</em> nil]
        <pre class="example">音频播放结束时的回调函数，回调函数的调用形式如下：
 cbFnc(result)
 result表示播放结果：
                   0-播放成功结束；
                   1-播放出错
                   2-播放优先级不够，没有播放
                   3-传入的参数出错，没有播放
                   4-被新的播放请求中止
                   5-调用audio.stop接口主动停止</pre>
        </li>
        <li><span class="parameter">dup</span>
            <span class="types"><span class="type">bool</span></span>
         [<em>此参数可选，默认值为：</em> nil]
        <pre class="example">是否循环播放，true循环，false或者nil不循环</pre>
        </li>
        <li><span class="parameter">dupInterval</span>
            <span class="types"><span class="type">number</span></span>
         [<em>此参数可选，默认值为：</em> 0]
        <pre class="example">循环播放间隔(单位毫秒)，dup为true时，此值才有意义</pre>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">result，bool或者nil类型，同步调用成功返回true，否则返回false</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">audio.play(<span class="number">0</span>,<span class="string">"FILE"</span>,<span class="string">"/lua/call.mp3"</span>)</pre></il>
        <li><pre class="example">audio.play(<span class="number">0</span>,<span class="string">"FILE"</span>,<span class="string">"/lua/call.mp3"</span>,<span class="number">7</span>)</pre></il>
        <li><pre class="example">audio.play(<span class="number">0</span>,<span class="string">"FILE"</span>,<span class="string">"/lua/call.mp3"</span>,<span class="number">7</span>,cbFnc)</pre></il>
        <li><pre class="example">更多用法参考demo/audio/testAudio.lua</pre></il>
    </ul>

</dd>
    <dt>
    <a name = "stop"></a>
    <strong  style="color: red;">
    stop (<strong  style="color: green;">[cbFnc=nil]</strong>)
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">停止音频播放</pre>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">cbFnc</span>
            <span class="types"><span class="type">function</span></span>
         [<em>此参数可选，默认值为：</em> nil]
        <pre class="example">停止音频播放的回调函数(停止结果通过此函数通知用户)，回调函数的调用形式为：
      cbFnc(result)
      result：number类型
              0表示停止成功</pre>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">nil</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">audio.stop()</pre></il>
    </ul>

</dd>
    <dt>
    <a name = "setVolume"></a>
    <strong  style="color: red;">
    setVolume (vol)
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">设置喇叭音量等级</pre>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">vol</span>
            <span class="types"><span class="type">number</span></span>
        <pre class="example">音量值为0-7，0为静音</pre>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">bool result，设置成功返回true，失败返回false</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">audio.setVolume(<span class="number">7</span>)</pre></il>
    </ul>

</dd>
    <dt>
    <a name = "setCallVolume"></a>
    <strong  style="color: red;">
    setCallVolume (vol)
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">设置通话音量等级</pre>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">vol</span>
            <span class="types"><span class="type">number</span></span>
        <pre class="example">音量值为0-7，0为静音</pre>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">bool result，设置成功返回true，失败返回false</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">audio.setCallVolume(<span class="number">7</span>)</pre></il>
    </ul>

</dd>
    <dt>
    <a name = "setMicGain"></a>
    <strong  style="color: red;">
    setMicGain (mode, level)
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">设置mic增益等级
 通话时mic增益在通话建立成功之后设置才有效
 录音mic增益设置后实时生效</pre>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">mode</span>
            <span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
        <pre class="example">增益类型
      "call"表示通话中mic增益
      "record"表示录音mic增益</pre>
        </li>
        <li><span class="parameter">level</span>
            <span class="types"><span class="type">number</span></span>
        <pre class="example">增益等级，取值为0-7</pre>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">bool result，设置成功返回true，失败返回false</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">audio.setMicGain(<span class="string">"record"</span>,<span class="number">7</span>)，设置录音时mic增益为<span class="number">7</span>级</pre></il>
    </ul>

</dd>
    <dt>
    <a name = "getVolume"></a>
    <strong  style="color: red;">
    getVolume ()
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">获取喇叭音量等级</pre>



    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">number vol，喇叭音量等级</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">audio.getVolume()</pre></il>
    </ul>

</dd>
    <dt>
    <a name = "getCallVolume"></a>
    <strong  style="color: red;">
    getCallVolume ()
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">获取通话音量等级</pre>



    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">number vol，通话音量等级</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">audio.getCallVolume()</pre></il>
    </ul>

</dd>
    <dt>
    <a name = "setStrategy"></a>
    <strong  style="color: red;">
    setStrategy (strategy)
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">设置优先级相同时的播放策略</pre>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">strategy</span>
            <span class="types"><span class="type">number</span></span>
        <pre class="example">优先级相同时的播放策略；
                   0：表示继续播放正在播放的音频，忽略请求播放的新音频
                   1：表示停止正在播放的音频，播放请求播放的新音频</pre>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">nil</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">audio.setStrategy(<span class="number">0</span>)</pre></il>
        <li><pre class="example">audio.setStrategy(<span class="number">1</span>)</pre></il>
    </ul>

</dd>
    <dt>
    <a name = "setTTSSpeed"></a>
    <strong  style="color: red;">
    setTTSSpeed (speed)
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">设置TTS朗读速度</pre>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">speed</span>
            <span class="types"><span class="type">number</span></span>
        <pre class="example">速度范围为0-100，默认50</pre>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">bool result，设置成功返回true，失败返回false</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">audio.setTTSSpeed(<span class="number">70</span>)</pre></il>
    </ul>

</dd>
    <dt>
    <a name = "setChannel"></a>
    <strong  style="color: red;">
    setChannel (<strong  style="color: green;">[output=2]</strong><strong  style="color: green;">[, input=0]</strong>)
    </strong>
    </dt>
    <dd>
    <pre class="example"  style="color: red;">设置音频输入、输出通道
 设置后实时生效</pre>


    <h3>Parameters:</h3>
    <ul>
        <li><span class="parameter">output</span>
            <span class="types"><span class="type">number</span></span>
         [<em>此参数可选，默认值为：</em> 2]
        <pre class="example">0：earphone听筒    1：headphone耳机    2：speaker喇叭</pre>
        </li>
        <li><span class="parameter">input</span>
            <span class="types"><span class="type">number</span></span>
         [<em>此参数可选，默认值为：</em> 0]
        <pre class="example"> 0：主mic    3：耳机mic</pre>
        </li>
    </ul>

    <h3>Returns:</h3>
    <ul>
        <li>
        <pre class="example">nil</pre></il>
    </ul>



    <h3>Usage:</h3>
    <ul>
        <li><pre class="example">设置为听筒输出：audio.setChannel(<span class="number">0</span>)
设置为耳机输出：audio.setChannel(<span class="number">1</span>)
设置为喇叭输出：audio.setChannel(<span class="number">2</span>)
设置为喇叭输出、耳机mic输入：audio.setChannel(<span class="number">2</span>,<span class="number">3</span>)</pre></il>
    </ul>

</dd>
</dl>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-08-02 13:53:19 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

